package com.rabbitmq.死信队列.过期时间;

import com.rabbitmq.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;

import java.nio.charset.StandardCharsets;

/**
 * @Auther: liyanhao
 * @Description: 死信队列☞生产者
 * @Date: 2022/5/11 22:24
 * @Version: v1.0
 */
public class Producer {
    //普通交换机的名称
    public static final String NORMAL_EXCHANGE = "normal_exchange";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        // 死信消息 设置TTl时间 time to live 存活时间 单位毫秒
        AMQP.BasicProperties properties = new AMQP.BasicProperties()
                .builder().expiration("10000").build();

        for (int i = 1; i < 11; i++) {
            String message = "info:" + i;
            channel.basicPublish(NORMAL_EXCHANGE, "zhangsan",
                    properties, message.getBytes(StandardCharsets.UTF_8));
        }
    }

}
